package slidingWindowAlgorithm.re11_01;

import test6_8.Solution;

public class HuaWei1 {

    //TODO:2023/11/1 面试的时候写的暴力解法
    public   int maxVowels(String s,int k){
        int ans=0;
        int len = s.length();
        for (int i = 0; i <=len-k ; i++) {
            String s1 = s.substring(i, i + k);
            int i1 = find(s1);
            ans=Math.max(i1,ans);
        }
        return  ans;
    }
    public  int find(String s){
        int ans=0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            switch (c){
                case 'a': ans++;break;
                case 'e':ans++;break;
                case 'i':ans++;break;
                case 'o':ans++;break;
                case 'u':ans++;break;
                default:break;
            }
        }
        return ans;
    }

    //TODO:2023/11/1 下来写的滑动窗口的写法

    public int maxVowels1(String s, int k) {
    //TODO:2023/11/1  这个想法 在面试的时候也有想起来过
        int[] record=new int[26];
        record['a'-'a']=1;
        record['e'-'a']=1;
        record['i'-'a']=1;
        record['o'-'a']=1;
        record['u'-'a']=1;
        int max=0;
        int count=0;
        for(int i=0;i<s.length()&&i<k;i++){
            if(record[s.charAt(i)-'a']==1){
                count++;
            }
        }
        max=count;
        for(int i=k;i<s.length();i++){
            if(record[s.charAt(i)-'a']==1){
                count++;
            }
            //TODO:2023/11/1 这里是整个滑动窗口的精华所在
            if(record[s.charAt(i-k)-'a']==1){
                count--;
            }
            max=Math.max(count,max);
        }

        return max;
    }


    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.maxVowels("aeiou", 2));
    }
}
